package com.practice.autoconfigure.redisson;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.SingleServerConfig;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.redisson.config.Config;

import java.util.Objects;

/**
 * @author yangdejun
 * @date 2021/11/1 16:00
 */
@Configuration
public class RdissonConfig {

    @Bean
    public RedissonClient redissonClient(RedissonProperties properties) {
        if (Objects.isNull(properties.getServerAddress())) {
            return null;
        }
        Config config = new Config();
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setAddress(properties.getServerAddress() + ":" + properties.getPort())
                .setPassword(properties.getPassword());
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
